package com.flyaudio.xiaopengautopilot.util;

public class ByteUtil {

    public static String hexStringToByte(String hex) {
        int i = Integer.parseInt(hex, 16);
        String str2 = Integer.toBinaryString(i);
        return str2;
    }

    public static String bytes2HexString(byte[] b) {
        String ret = "";
        try {
            if (b.length > 0) {
                for (int i = 0; i < b.length; i++) {
                    String hex = Integer.toHexString(b[i] & 0xFF);
                    if (hex.length() == 1) {
                        hex = '0' + hex;
                    }
                    if (hex.length() == 2) {
                        hex = " " + hex;
                    }
                    ret += hex;
                }
            }
        } catch (Exception e) {

        }
        return ret;
    }

    public static String bytes2HexString2(byte[] b) {
        String r = "";

        for (int i = 0; i < b.length; i++) {
            String hex = Integer.toHexString(b[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            r += hex.toUpperCase();
        }
        return r;
    }
}
